package xin.nick.common.handler;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;

/**
 * 异常过滤器
 * @author Nick
 * @since 2022/7/21/021
 */

//@Component
//@WebFilter
//@Order(-1)
public class ExceptionFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        try {
            System.out.println("-------------------sdfdsf");
            filterChain.doFilter(servletRequest, servletResponse);
        } catch (Exception e) {

            System.out.println("报错了,,不看一下吗");
            // 异常捕获，发送到error controller
            servletRequest.setAttribute("filter.error", e);
            // 将异常分发到/error/exthrow控制器
//            servletRequest.getRequestDispatcher("/error/exthrow").forward(servletRequest, servletResponse);
        }
    }
}
